namespace KBEngine
{
  	using UnityEngine; 
	using System; 
	using System.Collections; 
	using System.Collections.Generic;
	using System.Linq;
	
    public class Account : AccountBase 
    {		
		public Account() : base()
		{
		}
		
		public override void __init__()
		{
			// 注册事件
			Event.registerIn("reqCreateAvatar", this, "reqCreateAvatar");
			Event.registerIn("reqRemoveAvatar", this, "reqRemoveAvatar");
			Event.registerIn("selectAvatarGame", this, "selectAvatarGame");

			// 触发登陆成功事件
			Event.fireOut("onLoginSuccessfully", new object[]{KBEngineApp.app.entity_uuid, id, this});
			
			// 向服务端请求获得角色列表
			baseEntityCall.reqAvatarCount();
		}

		public override void onDestroy ()
		{
			KBEngine.Event.deregisterIn(this);
		}

        // 服务端响应 创建角色
        public override void onCreateAvatarResult(Byte retcode, UInt32 avatarCount)
		{
			if(retcode != 0)
			{
				Dbg.ERROR_MSG("Account::onCreateAvatarResult: retcode=" + retcode);
			}

			// ui event
			Event.fireOut("onCreateAvatarResult", new object[]{retcode, avatarCount });
		}
		
        // 删除默认角色
		public override void onRemoveAvatar(UInt64 dbid)
		{
			Dbg.DEBUG_MSG("Account::onRemoveAvatar: dbid=" + dbid);

			// ui event
			Event.fireOut("onRemoveAvatar", new object[]{dbid});
		}

        // 请求默认角色个数
        public override void onReqAvatarCount(UInt32 avatarCount)
		{				
			Dbg.DEBUG_MSG("Account::onReqAvatarList: avatarCount=" + avatarCount);

            // ui event
            Event.fireOut("onReqAvatarCount", new object[]{ avatarCount });
		}

        // 创建默认角色
		public void reqCreateAvatar(Byte roleType, string name)
		{
			Dbg.DEBUG_MSG("Account::reqCreateAvatar: roleType=" + roleType);
			baseEntityCall.reqCreateAvatar(roleType, name);
		}

        // 删除默认角色
		public void reqRemoveAvatar(string name)
		{
			Dbg.DEBUG_MSG("Account::reqRemoveAvatar: name=" + name);
			baseEntityCall.reqRemoveAvatar(name);
		}
		
        // 使用默认角色进入游戏
		public void selectAvatarGame()
		{
			Dbg.DEBUG_MSG("Account::selectAvatarGame.");
			baseEntityCall.selectAvatarGame();
		}
    }
} 
